﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;
using ThresholdAssistant.DataContract.Result;
using ThresholdAssistant.WebAPI.Models;
using ThresholdAssistant.WebAPI.Service;

namespace ThresholdAssistant.WebAPI.Controllers
{
    /// <summary>
    /// 群组控制器
    /// </summary>
    [Route("api/group")]
    public class GroupController : BaseController
    {
        /// <summary>
        /// 用户服务
        /// </summary>
        public MemberService UserService { get; set; }

        /// <summary>
        /// 生成入群二维码
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost("create-qr-code")]
        [AllowAnonymous]
        public async Task<ContractResult<InviteData>> CreateGroupQrCodeAsync(CreateGroupQrCodeParam param)
        {
            return await UserService.CreateGroupQrCodeAsync(param);
        }

        /// <summary>
        /// 获取群成员列表
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost("get-member-list")]
        [AllowAnonymous]
        public async Task<ContractResult<IEnumerable<MemberData>>> GetGroupMemberListAsync(GetGroupMemberListParam param)
        {
            return await UserService.GetGroupMemberListAsync(param);
        }

        /// <summary>
        /// 加入群组
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost("join")]
        [AllowAnonymous]
        public async Task<ContractResult<long>> JoinGroupAsync(JoinGroupParam param)
        {
            return await UserService.JoinGroupAsync(param);
        }

        /// <summary>
        /// 退出群组
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost("withdraw")]
        [AllowAnonymous]
        public async Task<ContractResult> WithdrawGroupAsync(WithdrawGroupParam param)
        {
            return await UserService.WithdrawGroupAsync(param);
        }

        /// <summary>
        /// 群内踢人
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost("kick")]
        [AllowAnonymous]
        public async Task<ContractResult> TickGroupAsync(TickGroupParam param)
        {
            return await UserService.TickGroupAsync(param);
        }
    }
}